<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../template/StakeholderTemplate.xhtml">

    <ui:define name="contentInsert">
        
        <h3>Outlets</h3>
        <p:panel id="panel" >
            <h:form>

                <p:ajaxStatus style="width:16px;height:16px;">
                    <f:facet name="start">
                        <h:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" />
                    </f:facet>
                    <f:facet name="complete"> 
                        <h:outputText value="" />
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />

                <br/>
                <br/>

                <p:dataTable value="#{outletManagerBean.getOutletsByStakeholder()}" var="o" paginator="true" rows="10"
                             onRowSelectUpdate="panel"
                             selection="#{outletManagerBean.selectedOutlet}"
                             selectionMode="single"
                             >

                    <p:column style="width: 10px" headerText="ID">
                        <f:facet name="header">Outlet Id</f:facet>
    			#{o.id}
                    </p:column>

                    <p:column style="width: 25px" headerText="Outlet Name" filterBy="#{o.outletName}" filterMatchMode="contains">
    			#{o.outletName}
                    </p:column>

                </p:dataTable>
                <br/>
                Click on a row in the table above to select an outlet for editing.
            </h:form> 
            
                 <br/>
   
                 <h4>Outlet Controls</h4>
                 <h:panelGrid columns="2">
                     <h5>Outlet ID: &nbsp;</h5> <h:outputLabel value="#{outletManagerBean.selectedOutlet.id}"/>
                     <h5>Outlet Name: &nbsp;</h5> <h:outputLabel value="#{outletManagerBean.selectedOutlet.outletName}"/> 
                     <h5>Phone Number: &nbsp;</h5> <h:outputLabel value="#{outletManagerBean.selectedOutlet.phoneNumber}"/> 
                     <h5>Address: &nbsp;</h5> <h:outputLabel value="#{outletManagerBean.selectedOutlet.address}"/> 
                 </h:panelGrid>
                 <br/>
                 <br/>
                 <br/>
                 <h:form>
                     <p:commandButton   value="Delete This Outlet" onclick="if (!confirm('Are you sure you want to delete outlet?')) return false"
                        action="#{outletManagerBean.deleteOutlet(outletManagerBean.selectedOutlet)}" ajax="false">
                     </p:commandButton>
                 </h:form>
                     
                 <h:form>    
                 <h5>Add New Outlet Manager</h5>
                     Enter the manager's FoodSage Account (email address).<br/>
                     <p:inputText id="manager_email"  value="#{outletManagerBean.outletManager_email}" required="true" requiredMessage="A valid email address is needed">
                         <f:validateRegex pattern="[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+"/>
                     </p:inputText>
                     <p:message for="manager_email"/>
                     <p:commandButton value="Add Manager" action="#{outletManagerBean.createOutletManager()}" ajax="false"/>                     
                 </h:form>
                 
                 <br/>
                 
                 <h:form>
                    <h5>Remove Outlet Manager</h5>
                    Choose the manager to be removed.<br/>
                    <h:selectOneMenu value="#{outletManagerBean.outletManager_email}" style="width:220px;">
                        <f:selectItems value="#{outletManagerBean.getOutletManagerEmailsbyOutlet()}"/>
                    </h:selectOneMenu>
                    <p:commandButton value="Remove this Manager" action="#{outletManagerBean.deleteOutletManager()}" ajax="false"/>
                 </h:form>
      
        
        </p:panel>
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

        
        
        
        
        
        

    </ui:define>

</ui:composition>